-
Notifications
You must be signed in to change notification settings - Fork 36
i18n-embed-fl: check args on MessageReference #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
i18n-embed-fl: check args on MessageReference #146
Conversation
Add `FluentLanguageLoader::with_fluent_message_and_bundle()`. This method functions like `with_fluent_message()`, but it also returns the `FluentBundle` which owns the message. This addition permits the closure to resolve `MessageReference` and to retrieve other messages on the same bundle.
The `fl!()` macro checks that all assigned arguments exist on
the message in question. But fluent messages can also refer to
other messages, and those messages can also have arguments.
```ftl
hello = Hello { to-you }
to-you = to you, {$name}!
```
Previous versions of the macro could not check arguments on
`MessageReference`s since it had no way to resolve them.
Bring the owning `FluentBundle` into scope so that message
references can be resolved. Some unnecessary generics on the
recursive functions are made concrete.
This patch requires an update to i18-embed for new API.
| .map(|m| m.value()) | ||
| .map(|p| args_from_pattern(p, bundle, args)); | ||
| } | ||
| _ => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we go ahead and match this enum exhaustively? The source enum is not marked #[non_exhaustive], which means that any additions on fluent's part can be considered breaking. Making our match exhaustive will detect any future additions to the AST with breakage here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Hello @kellpossible, can you assign a reviewer for this PR? |
|
Hi @cbs228 sorry I didn't see this until now! (Email notifications never seem to work for me, until someone comments), I'd be happy to review this, this coming week. |
|
Thanks @cbs228 this is a significant contribution! |
|
@cbs228 I published a new release with this change |
|
Thanks, I appreciate the new release! |
The
fl!()macro checks that all assigned arguments exist on the message in question. But fluent messages can also refer to other messages, and those messages can also have arguments.hello = Hello { to-you } to-you = to you, {$name}!Previous versions of
fl!()would not permit thenameargument to be bound.Resolving references to other messages requires access to the owning
FluentBundle. A variety of alternatives for granting this access are discussed in #144. This PR adds a new public API function,FluentLanguageLoader::with_fluent_message_and_bundle(), which passes both:to a closure.
With this new capability,
fl!macro is updated to properly supportMessageReference.This is an API-enhancing change for
i18n-embedand a bugfix fori18n-embed-fl.Closes #144.